package com.lx.oms.controller.controller;

import java.math.BigInteger;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.lx.oms.common.annotation.SysLog;
import com.lx.oms.common.controller.AbstractController;
import com.lx.oms.common.entity.Page;
import com.lx.oms.common.entity.R;
import com.lx.oms.controller.entity.UserEntity;
import com.lx.oms.controller.service.UserService;

/**
 * 用户表
 *
 * @author houzhong
 * @date 2018年7月10日 上午9:24:32
 */
@RestController
@RequestMapping("/sys/tuser")
public class UserController extends AbstractController {
	
	@Autowired
	private UserService userService;
	
	/**
	 * 列表
	 * @param params
	 * @return
	 */
	@RequestMapping("/list")
	public Page<UserEntity> list(@RequestBody Map<String, Object> params,String wxType) {
		params.put("wxType", wxType);
		return userService.listUser(params);
	}
		
	/**
	 * 新增
	 * @param tUser
	 * @return
	 */
	@SysLog("新增用户表")
	@RequestMapping("/save")
	public R save(@RequestBody UserEntity user) {
		user.setWxType(2);
		return userService.saveUser(user);
	}
	
	/**
	 * 根据id查询详情
	 * @param id
	 * @return
	 */
	@RequestMapping("/info")
	public R getById(@RequestBody String id) {
		return userService.getUserById(new BigInteger(id));
	}
	
	@RequestMapping("/userInfo")
	public R userInfo(String id) {
		return userService.getUserById(new BigInteger(id));
	}
	
	/**
	 * 修改
	 * @param tUser
	 * @return
	 */
	@SysLog("修改用户表")
	@RequestMapping("/update")
	public R update(@RequestBody UserEntity user) {
		return userService.updateUser(user);
	}
	
	/**
	 * 删除
	 * @param id
	 * @return
	 */
	@SysLog("删除用户表")
	@RequestMapping("/remove")
	public R batchRemove(@RequestBody String[] id) {
		return userService.batchRemove(id);
	}
	
	/**
	 * 启用账户
	 * @param id
	 * @return
	 */
	@SysLog("启用账户")
	@RequestMapping("/enable")
	public R updateUserEnable(@RequestBody String[] id) {
		return userService.updateUserEnable(id);
	}
	
	/**
	 * 禁用账户
	 * @param id
	 * @return
	 */
	@SysLog("禁用账户")
	@RequestMapping("/disable")
	public R updateUserDisable(@RequestBody String[] id) {
		return userService.updateUserDisable(id);
	}
	
}
